<?php
/**
 * Created by PhpStorm.
 * User: yzs
 * Date: 2018/1/25
 * Time: 15:13
 */


include("../phpQuery.php");

class pq extends phpQuery
{
   public $content;
   public $doc;
   public $minnr;

   public function __construct()
   {

   }

   public function newpq($html){
       phpQuery::selectDocument($html);
       $content=trim($html);
       $doc=phpQuery::newDocumentHTML($content);
       $this->content=$content;
       $this->doc=$doc;
       return $this;
   }

   public function qianhou($a){
        $xpath=pq($a)->getXpath();
        $this->minnr=pq($a)->htmlOuter();
        $s1=$s2="";
        $c=count($xpath);
        for($i=0;$i<$c-1;$i++){
            $class=($xpath[$i]['class']!="")?" class=\"{$xpath[$i]['class']}\"":"";
            $id=($xpath[$i]['id']!="")?" id=\"{$xpath[$i]['id']}\"":"";
            $span=str_repeat("\t",$i);
            $s1.=$span."<{$xpath[$i]['tagName']}{$class}{$id}>\r\n";
            $span=str_repeat("\t",($c-$i-2));
            $s2.="\r\n".$span."</{$xpath[$c-$i-2]['tagName']}>";
        }
        $span=str_repeat("\t",($c-1));
        return $s1.preg_replace("/^(.*)$/mix",$span."\\1",$this->minnr).$s2;
    }


}